package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingPlanController
 * @Author liangDong
 * @Date 2025-05-08  15:33
 */
@RestController
@RequestMapping("/nursing")
public class NursingPlanController extends BaseController {
    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping("/plan")
    public ResponseResult<List<NursingPlanVo>> getAll() {
        List<NursingPlanVo> list = nursingPlanService.getAll();
        return success(list);
    }

    @PostMapping("/plan")
    public ResponseResult addPlan(@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.add(nursingPlanDto);
        return success();
    }

    @GetMapping("/plan/search")
    public ResponseResult<PageResponse<NursingPlanVo>> page(
            @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "status", required = false) Integer status,
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        PageResponse<NursingPlanVo> nursingPlanInfo = nursingPlanService.page(name, status, pageNum, pageSize);
        return success(nursingPlanInfo);
    }

    @GetMapping("/plan/{id}")
    public ResponseResult<NursingPlanVo> getNursingPlanById(@PathVariable Long id) {
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        return success(nursingPlanVo);
    }

    @PutMapping("/plan/{id}")
    public ResponseResult updateNursingPlanById(@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.updateById(nursingPlanDto);
        return success();
    }

    @DeleteMapping("/plan/{id}")
    public ResponseResult deleteNursingPlanById(@PathVariable Integer id) {
        nursingPlanService.deleteById(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    public ResponseResult changeStatus(@PathVariable Integer id, @PathVariable Integer status) {
        nursingPlanService.updateStatus(id, status);
        return success();
    }
}
